package com.cxb.view;

import com.cxb.R;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

public class DiapadDialog extends Dialog implements
		android.view.View.OnClickListener {

	private Context mContext = null;
	private EditText et_diapadInput = null;

	public DiapadDialog(Context context) {

		super(context, R.style.diapad_dialog_theme);

		mContext = context;
		setContentView(R.layout.diapad_layout);
		getWindow().setType(WindowManager.LayoutParams.TYPE_PRIORITY_PHONE);
		WindowManager.LayoutParams p = getWindow().getAttributes();
		p.height = WindowManager.LayoutParams.FILL_PARENT;  
		p.width = WindowManager.LayoutParams.FILL_PARENT;
		
		et_diapadInput=(EditText) findViewById(R.id.et_diapad_input);

		findViewById(R.id.bt_0).setOnClickListener(this);
		findViewById(R.id.bt_1).setOnClickListener(this);
		findViewById(R.id.bt_2).setOnClickListener(this);
		findViewById(R.id.bt_3).setOnClickListener(this);
		findViewById(R.id.bt_4).setOnClickListener(this);
		findViewById(R.id.bt_5).setOnClickListener(this);
		findViewById(R.id.bt_6).setOnClickListener(this);
		findViewById(R.id.bt_7).setOnClickListener(this);
		findViewById(R.id.bt_8).setOnClickListener(this);
		findViewById(R.id.bt_9).setOnClickListener(this);
		findViewById(R.id.bt_star).setOnClickListener(this);
		findViewById(R.id.bt_pound).setOnClickListener(this);

		findViewById(R.id.bt_back).setOnClickListener(this);
	}

	@Override
	public void show() {
		if(et_diapadInput!=null){
			et_diapadInput.setText("");
		}
		super.show();
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		if (id == R.id.bt_back) {
			this.dismiss();
		} else {
			char keyValue = ((TextView) v).getText().charAt(0);
			Intent intent=new Intent("action.cxb.dtmf");
			intent.putExtra("dtmf_key", keyValue+"");
			mContext.sendBroadcast(intent);
			et_diapadInput.append(keyValue+"");
		}
	}

}
